package com.alibaba.yinan.domain.task.factory;

import com.alibaba.yinan.domain.task.enums.DeviceType;
import com.alibaba.yinan.domain.task.Task;
import com.alibaba.yinan.domain.task.enums.TaskStatus;
import com.alibaba.yinan.domain.task.enums.TaskType;
import com.alibaba.yinan.client.dto.CreateAndDispatchTaskCmd;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @ClassName TaskFactory
 * @Author mengke
 * @create 2025/8/3 20:49
 * @Description
 */
public class TaskFactory {

    public static Task create(CreateAndDispatchTaskCmd cmd) {
        Task task = new Task();

        task.setId(UUID.randomUUID().toString());
        task.setProcessInstanceId(cmd.getProcessInstanceId());
        task.setNodeId(cmd.getNodeId());

        task.setType(TaskType.valueOf(cmd.getType()));
        task.setStatus(TaskStatus.CREATED);

        task.setDependencies(cmd.getDependencies());
        task.setTargetDeviceType(DeviceType.valueOf(cmd.getTargetDeviceType()));
        task.setDispatchPolicyKeys(cmd.getDispatchPolicyKeys());

        task.setCreateTime(Instant.now());

        return task;
    }
}
